<template>
  <div class="agencySearch">
    <el-dialog
      :visible.sync="visible"
      width="65%"
      destroy-on-close
      :close-on-click-modal="false"
      :title="title"
      @open="openHandle"
      @close="resetForm"
    >
      <ContentWrap>
        <el-row>
          <el-form
            ref="searchForm"
            :model="formData"
            :rules="formRules"
            label-width="80px"
          >
            <el-col :span="8">
              <el-form-item prop="name" label="客户经理姓名">
                <el-input v-model="formData.name" clearable placeholder="请输入客户经理姓名" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="phone" label="联系电话">
                <el-input v-model="formData.phone" clearable placeholder="请输入联系电话" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <Button @click="resetClick('searchForm')">重置</Button>
                <Button type="primary" enter @click="searchClick('searchForm')">查询</Button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
        <table-box
          ref="detailTable"
          height="260"
          no-request
          :other-filters="filterParams"
          :table-config="detailTableConfig"
        />
      </ContentWrap>
    </el-dialog>
  </div>
</template>

<script>
import ContentWrap from '@/components/ContentWrap'
import Button from '@/components/Button'
import { JsonToUrl } from '@/utils/params-format'
export default {
  components: {
    ContentWrap,
    Button
  },
  props: {
    toggle: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      title: '客户经理信息',
      formData: {
        name: '', // 客户经理姓名
        phone: '' // 联系电话
      },
      formRules: {
        // customerTel: [
        //   { pattern: /^1\d{10}$/, message: '请输入正确的联系电话', trigger: 'change' }
        // ]
      },
      filterParams: [],
      url: '',
      detailTableConfig: {
        interfacePath: '',
        pageFlag: true,
        hideFuncBar: true,
        // 表格字段信息配置
        setting: [
          {
            prop: 'customerId',
            label: '序号',
            align: 'center',
            formatData: (val) => { return val.keyIndex + 1 }
          }, {
            prop: 'code',
            label: '客户经理编码',
            align: 'center'
          }, {
            prop: 'name',
            label: '客户经理姓名',
            align: 'center'
          }, {
            prop: 'sex',
            label: '性别',
            align: 'center',
            formatData: (val) => {
              if (val.sex === 1) return '男'
              if (val.sex === 0) return '女'
              return '--'
            }
          }, {
            prop: 'phone',
            label: '联系电话',
            align: 'center'
          }
        ]
      },
      visible: false
    }
  },
  watch: {
    toggle(newVal, oldVal) {
      this.visible = newVal
    }
  },
  created() {},
  mounted() {
  },
  methods: {
    /**
     * 提交查询
     */
    searchClick(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // this.filterParams = [...JsonToUrl(this.formData)]
          this.detailTableConfig.interfacePath = `${this.url}${JsonToUrl(this.formData)}`
          this.$nextTick(() => {
            this.$refs.detailTable.initTableData()
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 打开时
    openHandle() {
      this.url = `/call-center/api/v1/mscInfo/account/${this.row.id}/page`
      this.detailTableConfig.interfacePath = this.url
    },
    /**
     * 重置搜索
     */
    resetClick(formName) {
      this.$refs[formName].resetFields()
    },
    resetForm() {
      this.visible = false
      this.$emit('modelClose')
      this.$refs.searchForm.resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
